package javafxapp;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class LineChartSample2 extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("Line Chart Sample 2");
        //defining the axes
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();
        xAxis.setLabel("Number of Month");
        //creating the chart
        final LineChart<Number, Number> lineChart =
                new LineChart<>(xAxis, yAxis);

        lineChart.setTitle("Stock Monitoring, 2013");
        XYChart.Series series = createSeries();

        AnchorPane page;
        try {
            page = (AnchorPane) FXMLLoader.load(SimpleJavaFxAppWithSceneBuilderFxmlFile.class.getResource("SimpleGuiFromSceneBuilder.fxml"));
            Scene scene = new Scene(page);
            lineChart.getData().add(series);
            
            Rectangle r = new Rectangle(25,25,250,250);
            r.setFill(Color.BLUE);

            
           LineChart lineChartOnGui = null;
            
            page.getChildren().add(r);
            page.getChildren().add(lineChart);
            page.getChildren().indexOf(lineChartOnGui);
            System.out.println("page.getChildren().indexOf(lineChartOnGui):" +  page.getChildren().indexOf(lineChartOnGui));
            stage.setScene(scene);
            stage.show();
        } catch (IOException ex) {
            Logger.getLogger(LineChartSample2.class.getName()).log(Level.SEVERE, null, ex);
        }


    }

    public static void main(String[] args) {
        launch(args);
    }

    private XYChart.Series createSeries() {
        //defining a series
        XYChart.Series series = new XYChart.Series();
        series.setName("My portfolio");
        //populating the series with data
        series.getData().add(new XYChart.Data(-3, 23));
        series.getData().add(new XYChart.Data(2, 14));
        series.getData().add(new XYChart.Data(3, 15));
        series.getData().add(new XYChart.Data(4, 24));
        series.getData().add(new XYChart.Data(5, 34));
        series.getData().add(new XYChart.Data(6, 36));
        series.getData().add(new XYChart.Data(7, 122));
        series.getData().add(new XYChart.Data(8, 45));
        series.getData().add(new XYChart.Data(-9, 43));
        series.getData().add(new XYChart.Data(120, 17));
        series.getData().add(new XYChart.Data(11, 29));
        series.getData().add(new XYChart.Data(12, 125));
        series.getData().add(new XYChart.Data(122.221, -1212.12));
        return series;
    }
}